package com.smartleanx.module.hrm.controller.admin.risk;

import com.smartleanx.framework.security.core.annotations.PreAuthenticated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import java.util.*;

import com.smartleanx.framework.common.pojo.CommonResult;

import static com.smartleanx.framework.common.pojo.CommonResult.success;

import com.smartleanx.module.hrm.controller.admin.risk.vo.*;
import com.smartleanx.module.hrm.service.risk.RiskService;

@Tag(name = "管理后台 - 风险点")
@RestController
@RequestMapping("/hrm/risk")
@Validated
public class RiskController {

    @Resource
    private RiskService riskService;

    @GetMapping("/getProfile")
    @Operation(summary = "获得风险概况")
    // @PreAuthorize("@ss.hasPermission('hrm:risk:query')")
    @PreAuthenticated
    public CommonResult<RiskProfileRespVO> getProfile() {
        return success(riskService.getProfile());
    }

    @GetMapping("/getRiskEmployee")
    @Operation(summary = "获得风险员工")
    // @PreAuthorize("@ss.hasPermission('hrm:risk:query')")
    @PreAuthenticated
    public CommonResult<List<RiskEmployeeRespVO>> getRiskEmployee(RiskQueryReqVO queryReqVO) {
        return success(riskService.getRiskEmployee(queryReqVO));
    }

    // @GetMapping("/getRiskEmployeeByRisk")
    // @Operation(summary = "获得涉及风险的员工")
    // // @PreAuthorize("@ss.hasPermission('hrm:risk:query')")
    // @PreAuthenticated
    // public CommonResult<List<RiskEmployeeRespVO>> getRiskEmployee(RiskQueryReqVO queryReqVO) {
    //     return success(riskService.getRiskEmployee(queryReqVO));
    // }

    @GetMapping("/getRiskRegulationByRisk")
    @Operation(summary = "获得涉及风险的制度")
    // @PreAuthorize("@ss.hasPermission('hrm:risk:query')")
    @Parameter(description = "风险类型id", required = true, example = "17")
    @PreAuthenticated
    public CommonResult<List<RiskRegulationRespVO>> getRiskRegulation(@RequestParam(value = "riskId", defaultValue = "17") Long riskId) {
        return success(riskService.getRiskRegulation(riskId));
    }

    @PostMapping("/cancelRiskEmp")
    @Operation(summary = "取消风险员工")
    @PreAuthenticated
    public CommonResult<Boolean> cancelRiskEmp(@RequestBody @Validated RiskCancelRiskEmpReqVO reqVO) {
        riskService.cancelRiskEmp(reqVO);
        return success(true);
    }

    @PostMapping("/cancelEmpRisk")
    @Operation(summary = "取消员工风险")
    @PreAuthenticated
    public CommonResult<Boolean> cancelEmpRisk(@RequestBody @Validated RiskCancelEmpRiskReqVO reqVO) {
        riskService.cancelEmpRisk(reqVO);
        return success(true);
    }

    @GetMapping("/getDetail")
    @Operation(summary = "获得风险详情")
    @Parameter(description = "风险类型", required = false, example = "1")
    // @PreAuthorize("@ss.hasPermission('hrm:risk-type:query')")
    @PreAuthenticated
    public CommonResult<RiskDetailRespVO> getDetail(@RequestParam(name = "riskLevel", required = false) Integer riskLevel) {
        return success(riskService.getDetail(riskLevel));
    }
}